package view;

import java.util.ArrayList;
import java.util.List;






import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
import javax.inject.Inject;

import controller.SalesCardController;
import controller.TimeCardController;
import entity.Contractor;
import entity.TimeCard;


@ManagedBean
@ViewScoped
public class ListOfTimeCards {

	@Inject TimeCardController controller;
	private List<TimeCard> listTimeCards;
	private List<TimeCard> deletedTimeCards=new ArrayList<TimeCard>();
	@PostConstruct
	private void LoadList(){
		Login login=(Login)FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("login");
		listTimeCards=controller.ListOfTimeCards((Contractor)login.getEmployee());
	}
	public List<TimeCard> getListTimeCards() {
		return listTimeCards;
	}
	public void setListTimeCards(List<TimeCard> listTimeCards) {
		this.listTimeCards = listTimeCards;
	}
	public void AddListDeletedTimeCard(TimeCard card){
		if(!deletedTimeCards.contains(card)){
			deletedTimeCards.add(card);
		}else{
			deletedTimeCards.remove(card);
		}
	}
	public String DeleteTimeCards(){
		for(int i=0;i<deletedTimeCards.size();i++){
			int value=controller.deleteTimeCard(deletedTimeCards.get(i));
			}
		deletedTimeCards.clear();
		return "ListTimeCard?faces-redirect=true";
	}
}
